package com.example.alphaspeed;


import android.os.Bundle;
import android.view.View;
import android.widget.Toast;

import androidx.annotation.Nullable;
import androidx.appcompat.app.AppCompatActivity;

import com.alpha.runes.core.RunesManager;
import com.alpha.runes.core.RunesStatusCode;

import java.util.HashMap;

public class MainActivity extends AppCompatActivity {

    boolean switchButton = true;

    @Override
    public void onCreate(@Nullable Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_main);
    }

    @Override
    protected void onResume() {
        super.onResume();

        HashMap<String, String> configHashMap = new HashMap<>();
//        configHashMap.put("appKey", "1b6708126046e9db03cd33a9e9f8e9b7");
        configHashMap.put("appKey", "e123849cae39422198a97d61281ca2d0");
//        configHashMap.put("channelCode", "S9fMtIgZMQIIF7oR");
        configHashMap.put("channelCode", "d8b8cae3e35e48e1");
        configHashMap.put("floatBall", "1");
        configHashMap.put("rate", "10");

//        initAlphaSpeed(configHashMap);

        findViewById(R.id.start).setOnClickListener(
                new View.OnClickListener() {
                    @Override
                    public void onClick(View view) {
                        Toast.makeText(MainActivity.this, "点我",Toast.LENGTH_SHORT).show();


                        if (switchButton) {
//                            RunesManager.getInstance().init(
//                                    configHashMap,
//                                    MainActivity.this,
//                                    new RunesManager.InitRunesManagerCallback() {
//                                        @Override
//                                        public void onSuccess() {
//                                            Toast.makeText(MainActivity.this, "成功开启", Toast.LENGTH_SHORT).show();
//                                        }
//
//                                        @Override
//                                        public void onFailed(RunesStatusCode runesStatusCode) {
//                                            if (runesStatusCode != null) {
//                                                Toast.makeText(MainActivity.this,
//                                                                runesStatusCode.getMsg() + "===" + runesStatusCode.getCode(),
//                                                                Toast.LENGTH_SHORT)
//                                                        .show();
//
//                                            }
//
//                                        }
//                                    });
                            initAlphaSpeed(configHashMap);
                            switchButton = false;
                        }
                    }
                }
        );
    }

    private void initAlphaSpeed(HashMap<String, String> configHashMap) {
        RunesManager.getInstance().init(
                configHashMap,
                MainActivity.this,
                new RunesManager.InitRunesManagerCallback() {
                    @Override
                    public void onSuccess() {
                        Toast.makeText(MainActivity.this, "成功开启", Toast.LENGTH_SHORT).show();
                    }

                    @Override
                    public void onFailed(RunesStatusCode runesStatusCode) {
                        if (runesStatusCode != null) {
                            Toast.makeText(MainActivity.this,
                                            runesStatusCode.getMsg() + "===" + runesStatusCode.getCode(),
                                            Toast.LENGTH_SHORT)
                                    .show();

                        }

                    }
                });
    }
}
